package cn.edu.zjicm.wordsnet_d.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.adapter.common.SortedListAdapter;
import cn.edu.zjicm.wordsnet_d.data.OneWord;
import cn.edu.zjicm.wordsnet_d.util.LogUtil;
import cn.edu.zjicm.wordsnet_d.util.TypefaceUtil;
import cn.edu.zjicm.wordsnet_d.view.WordSummaryView;

public class WordListForPhraseAdapter extends SortedListAdapter<OneWord> {

	private Context mContext;
	private ArrayList<OneWord> list;
	private LayoutInflater mInflater;
	private View view;

	public WordListForPhraseAdapter(Context mContext, ArrayList<OneWord> list) {
		this.mContext = mContext;
		this.list = list;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			view = mInflater.inflate(R.layout.view_word_note_item, null);
			WordSummaryView holder = new WordSummaryView();
			holder.word = (TextView) view.findViewById(R.id.word_note_item_word);
			holder.phe = (TextView) view.findViewById(R.id.word_note_item_phe);
			TypefaceUtil.getInstance(mContext).setTypeface(holder.phe);
			holder.traslation = (TextView) view.findViewById(R.id.word_note_item_translation);
			holder.wordCheckBox = (CheckBox) view.findViewById(R.id.word_note_item_checkbox);
			view.setTag(holder);
			convertView = view;
		}
		final OneWord word = getItem(position);
		convertView.setClickable(false);
		final WordSummaryView holder = (WordSummaryView) convertView.getTag();
		holder.word.setText(word.getLemma());
		holder.phe.setText(word.getPhonetic());
		holder.traslation.setText(word.getSensesSenior());
		holder.wordCheckBox.setVisibility(View.GONE);

		return convertView;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public OneWord getItem(int position) {
		return list.get(position);
	}
}
